package com.yubest.rabbitmq.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FanoutCustomer {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("test.fanout.queue1"),
                    exchange = @Exchange(name = "test.fanout.exchange", type = ExchangeTypes.FANOUT)))
    public void consumer1(String msg) {
        log.info("类型【fanout】，交换机【test.fanout.exchange】，队列【test.fanout.queue1】，收到的消息【{}】", msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("test.fanout.queue2"),
                    exchange = @Exchange(name = "test.fanout.exchange", type = ExchangeTypes.FANOUT)))
    public void consumer2(String msg) {
        log.info("类型【fanout】，交换机【test.fanout.exchange】，队列【test.fanout.queue2】，收到的消息【{}】", msg);
    }
}
